// *********************************************************
//      Copyright (c) Kosta Gaitanis
//      All rights reserved
//
//      k.gaitanis@gmail.com
//
// *********************************************************

#ifndef TESTCAMERA_H
#define TESTCAMERA_H

#include <QObject>
#include <QDebug>
#include <QtTest/QtTest>

#include "../RVA/Camera.h"

class TestCamera : public QObject
{
  Q_OBJECT
public:
    explicit TestCamera(QObject *parent = 0) :
        QObject(parent),
        m_camera(new Camera())
    {}


private:
    Camera *m_camera;

private slots:
    void cleanupTestCase() {
        delete m_camera;
    }

    void testFrustum() {
        m_camera->setAspectRatio(2);
        m_camera->setFieldOfView(60);
        m_camera->setNearLimit(10);


        QSizeF f1 = m_camera->getFrustumSize();

        QVERIFY(qAbs(f1.width() - 11.547) < 0.0001);
        QVERIFY(qAbs(f1.height() - 5.7735) < 0.0001);

        m_camera->setAspectRatio(1.69);
        m_camera->setFieldOfView(45);
        m_camera->setNearLimit(1);

        QSizeF f2 = m_camera->getFrustumSize();
        QVERIFY(qAbs(f2.width() - 0.700021) < 0.0001);
        QVERIFY(qAbs(f2.height() - 0.414214) < 0.0001);
    }

    void testCameraPosition() {
        m_camera->setTargetPosition(0, 0, 0);
        m_camera->setCameraPosition(1, -2, 3);
        m_camera->setUpDirection(10, 10, 10);

        Matrix m = m_camera->getCameraMatrix();
        Matrix cm(0.811107,	-0.324443,	-0.486664,	0.0,
                  0.520266,	0.780399,	0.346844,	0.0,
                  0.267261,	-0.534522,	0.801784,	-3.74166,
                  0.0,	0.0,	0.0,	1);

        QVERIFY(m == cm);

        m_camera->setTargetPosition(50, 19, -23);
        m_camera->setCameraPosition(1, 2, -3);
        m_camera->setUpDirection(1, -2, -3);

        m = m_camera->getCameraMatrix();
        cm = Matrix(-0.469078,	0.654648,	-0.592791,	-2.61859,
                    -0.0542476,	-0.691309,	-0.72052,	-0.724693,
                    -0.881489,	-0.305823,	0.359791,	2.57251,
                    0,	0,	0,	1);
        QVERIFY(m == cm);
    }

};

#endif // TESTCAMERA_H
